package com.yonyou.crm.sprc.opportunity.rmimpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.common.page.entity.Page;
import com.yonyou.crm.sprc.opportunity.entity.AppOpportunityStageVO;
import com.yonyou.crm.sprc.opportunity.entity.OpportunityBVO;
import com.yonyou.crm.sprc.opportunity.entity.OpportunityVO;
import com.yonyou.crm.sprc.opportunity.rmitf.IOpportunityRmService;
import com.yonyou.crm.sprc.opportunity.service.OpportunityBBizServiceImpl;
import com.yonyou.crm.sprc.opportunity.service.OpportunityBizServiceImpl;

@Service("opportunityService")
public class OpportunityRmserviceImpl implements IOpportunityRmService {
    @Autowired
    private OpportunityBizServiceImpl bizService;

    @Autowired
    private OpportunityBBizServiceImpl bService;

    @Override
    public Page<OpportunityVO> getList(Page<OpportunityVO> requestPage, Map<String, Object> map) {
        return bizService.getList(requestPage, map);
    }
    @Override
    public List getFunnel(Map<String, Object> searchMap) {
        return bizService.getFunnel(searchMap);
    }

    @Override
    public Map<String, Object> getFilterConditon() {
        return bizService.getFilterConditon();
    }

    @Override
    public OpportunityVO getDetail(Long id) {
        return bizService.getDetail(id);
    }

    @Override
    public OpportunityVO insert(OpportunityVO opportunity,List<Map<String,Object>> stageList,List<Map<String,Object>> actionList) {
        OpportunityVO newOpportunity = bizService.insert(opportunity);
        bizService.insertMiddleTable(newOpportunity,stageList,actionList);
        OpportunityVO vo = bizService.getDetail(newOpportunity.getId());
        return vo;
    }

    @Override
    public OpportunityVO insert(OpportunityVO opportunity) {
        return bizService.insert(opportunity);
    }
    
    @Override
    public OpportunityVO insert(OpportunityVO opportunity, Map<String, Object> param) {
        return bizService.insert(opportunity, param);
    }

    @Override
    public OpportunityVO update(OpportunityVO opportunity) {
        return bizService.update(opportunity);
    }

    @Override
    public Map <String, Object> batchDelete(String[] idArray, Page<OpportunityVO> requestPage, Map<String, Object> map) {
        String message = bizService.batchDelete(idArray);
        Page<OpportunityVO> page = bizService.getList(requestPage, map);
        Map <String, Object> deleteResult = new HashMap<>();
        deleteResult.put("message", message);
        deleteResult.put("page", page);
        return deleteResult;

    }

    @Override
    public Page<OpportunityBVO> getChildList(Page<OpportunityBVO> childRequestPage, Map<String, Object> searchMap, Long opportunityID) {
        return bService.getPageByOpportunityID(childRequestPage,searchMap,opportunityID);
    }

	@Override
	public int delete(Long id) {
		return bizService.delete(id);
	}

   /* @Override
    public Page<OpportunityBVO> saveChildList(List<OpportunityBVO> bvoList, Long id, Page<OpportunityBVO> childRequestPage, Map<String, Object> searchMap) {
        bizService.saveChirld(bvoList);
        return bService.getPageByOpportunityID(childRequestPage,searchMap,id);
    }

    @Override
    public Page<OpportunityBVO> batchDeleteChild(String[] idArray, Long id, Page<OpportunityBVO> childRequestPage, Map<String, Object> searchMap) {
        bizService.batchDeleteChild(idArray, id);
        return bService.getPageByOpportunityID(childRequestPage,searchMap,id);
    }*/
	
	@Override
	public List<AppOpportunityStageVO> getStageListForOpportunity(Long id){
		return bizService.getStageListForOpportunity(id);
	}
	
	@Override
	public List<AppOpportunityStageVO> stageInfo(Map<String, Object> param){
		return bizService.stageInfo(param);
	}
    
	@Override
    public int saveAction(Map<String, Object> param){
    	return bizService.saveAction(param);
    }
	
	@Override
	public int insertFollow(Long id) {
		return bizService.saveFollow(id);
	}

	@Override
	public int deleteFollow(Long id) {
		return bizService.deleteFollow(id);
	}


    @Override
    public List<Map<String,Object>> getStageBybiztype(Long type){
        return bizService.getStageBybiztype(type);
    }

    @Override
    public List<Map<String,Object>> getActionBybiztype(Long type){
        return bizService.getActionBybiztype(type);
    }
    @Override
    public  List<Map<String,Object>> getResultById(Long id){
        return bizService.getResultById(id);
    }

    @Override
    public  List<Map<String,Object>> getStageById(Long id){
        return bizService.getStageById(id);
    }
    
	@Override
	public void win(Map<String, Object> paramMap){
		bizService.win(paramMap);
	}
	
	@Override
	public void lose(Map<String, Object> paramMap){
		bizService.lose(paramMap);
	}
    @Override
    public int finishAction(Map<String,Object> paramMap){
        return bizService.finishAction(paramMap);
    }

    @Override
    public int setCurrentStage(Map<String,Object> paramMap){
        return bizService.setCurrentStage(paramMap);
    }

    @Override
    public Map<String,Object> getFunnelMoney(Map<String, Object> searchMap){
        return bizService.getFunnelMoney(searchMap);
    }

    public OpportunityVO winOpp(OpportunityVO vo){
        OpportunityVO newVo =  bizService.updateVO(vo);
        return bizService.getDetail(newVo.getId());
    }

    public OpportunityVO lostOpp(OpportunityVO vo){
        OpportunityVO newVo =  bizService.updateVO(vo);
        return bizService.getDetail(newVo.getId());
    }

}
